﻿using System;
using System.Collections;
using System.Windows;
using System.Windows.Controls;
using jSLApp.Client.ApplicationBase;
using jSLCore.Client.Presentation.BaseControl.Selection;

namespace jSLApp.Client.Forms
{
    public partial class Forum : SelectControl
    {
        public Forum()
        {
            InitializeComponent();
        }


        private void Search()
        {
            DoWork("Поиск...",(sender, args) =>
                                  {
                                      args.Result = Communication.Proxy.SearchForum(args.String);
                                  },(o, eventArgs) =>
                                                        {
                                                            if(eventArgs.Error==null)
                                                            {
                                                                grid.ItemsSource = (IEnumerable) eventArgs.Result;
                                                            }
                                                        },txt.Text);
        }

        #region dialog

        public override ISelectableGrid GetSelectableGrid()
        {
            return grid;
        }
        
        protected override void AcceptButtonClicked()
        {
            Search();
        }

        public override void LoadInitialData()
        {
            Search();
        }

        public override Control GetControlForInitialFocus()
        {
            return txt;
        }

        #endregion

        private void createTopic_Clicked(object sender, RoutedEventArgs e)
        {
            MainContentContainer.Current.CreateTopic();
        }
    }
}
